using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using GuiLabs.Utils.Collections;

namespace FolderComparer
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void ButtonCheck_Click(object sender, EventArgs e)
		{
			if (!Path1.PathExists || !Path2.PathExists)
			{
				return;
			}
			Check(Path1.Path, Path2.Path);
		}

		public void Check(string path1, string path2)
		{
			List<FileInfo> files1 = GetAllFiles(path1);
			List<FileInfo> files2 = GetAllFiles(path2);

			Dict<FileInfo> fileSet2 = new Dict<FileInfo>();
			foreach (FileInfo fileInfo in files2)
			{
				fileSet2.Add(fileInfo.Name, fileInfo);
			}

			ListFilesNotFound.BeginUpdate();
			ListFilesNotFound.Items.Clear();
			foreach (FileInfo f in files1)
			{
				FileInfo found = fileSet2[f.Name];
				if (found == null)
				{
					ListFilesNotFound.Items.Add(f.FullName);
				}
				else
				{
					if (found.Length != f.Length)
					{
						ListFilesNotFound.Items.Add(f.FullName);
					}
				}
			}
			ListFilesNotFound.EndUpdate();

			MessageBox.Show("Done!");
		}

		private List<FileInfo> GetAllFiles(string p)
		{
			string[] files = Directory.GetFiles(p, "*.jpg", SearchOption.AllDirectories);
			List<FileInfo> result = new List<FileInfo>();
			foreach (string s in files)
			{
				FileInfo f = new FileInfo(s);
				result.Add(f);
			}
			return result;
		}
	}
}